//存放数据
const state = {
	openId: '',
	code: '',
	// authCode: '',
	userName: '',
	phone: '',
	avator: '/static/avator_icons/avator-default.png',
	userId: '',
	roleId: '',
	fileId: '',
	estatedId:'',
	selectedProject:'请选择'
}
//派生数据
const getters = {
	openId: (state) => state.openId,
	code: (state) => state.code,
	// authCode: (state) => state.authCode,
	userName: (state) => state.userName,
	phone: (state) => state.phone,
	avator: (state) => state.avator,
	userId: (state) => state.userId,
	roleId: (state) => state.roleId,
	estatedId:(state) => state.estatedId,
	selectedProject:(state) => state.selectedProject
}
//同步改变
const mutations = {
	setEstatedId(state, estatedId) {
		state.estatedId = estatedId
		uni.setStorageSync('estatedId', estatedId)
		// this.commit('user/saveEstatedId')
	},
	setSelectedProject(state, estatedId) {
		state.selectedProject = estatedId
		console.log(estatedId)
		uni.setStorageSync('selectedProject', estatedId)
		// this.commit('user/saveEstatedId')
	},
	setOpenId(state, openid) {
		state.openId = openid
		this.commit('user/saveToStorge')
	},
	setAvator(state, avator) {
		state.avator = avator
		this.commit('user/saveAvator')
	},
	setRoleId(state, role) {
		state.roleId = role
		this.commit('user/saveAuthCodeToStorge')
	},
	setUserName(state, user) {
		state.userName = user
		this.commit('user/saveUserNameToStorge')
	},
	setCode(state, code) {
		state.code = code
	},
	saveToStorge(state) {
		uni.setStorageSync('openId', state.openId)
	},
	saveRoleId(state) {
		uni.setStorageSync('roleId', state.roleId)
	},
	saveAvator(state) {
		uni.setStorageSync('avator', state.avator)

	},
	saveUserNameToStorge(state){
		uni.setStorageSync('userName',state.userName)
	}
}
//异步改变
const actions = {
	setOpenID({
		commit
	}, openid) {
		commit('setOpenId', openid)
	},
	setRoleID({
		commit
	}, payload) {
		commit('setRoleId', payload)
	},
	saveStorge({
		commit
	}, payload) {
		commit('saveToStorge', payload)
	},
	setCODE({
		commit
	}, code) {
		commit('setCode', code)
	},
	setAVATOR({
		commit
	}, avator) {
		commit('setAvator', avator)
	},
	setUserName({
		commit
	}, user) {
		commit('setUserName', user)
	},
}
export default {
	namespaced: false,
	state,
	actions,
	getters,
	mutations
}
